/**
 * 区域管理
 * @author luguoxiang
 * @date 2023-03-27
 * 开源项目：https://gitee.com/lgx1992/lg-soar 求star！请给我star！请帮我点个star！
 */
import { IConfigSchema } from '@/soar';
import { basePath } from './api';
import { MenuComponent } from '@/types/interface';

const strs = ['000000', '00000', '0000', '000', '00', '0', ''];

function getParentId(id: string) {
  if (id.length > 6) {
    id = id.substring(0, 6);
  }
  const v = Number(id + strs[id.length]);
  if (v % 10000 === 0) {
    return 0;
  }
  if (v % 100 === 0) {
    return Math.floor(v / 10000) * 10000;
  }
  return Math.floor(v / 100) * 100;
}

const fieldList: IConfigSchema<any>[] = [
  {
    field: 'id',
    label: 'ID',
    dataType: 'string',
    form: {
      rules: true,
      componentProps: {
        maxlength: 6,
      },
    },
  },
  {
    field: 'name',
    label: '名称',
    dataType: 'string',
    form: {
      rules: true,
    },
  },
  {
    field: 'status',
    label: '是否禁用',
    dataType: 'boolean',
  },
  {
    field: 'sort',
    label: '排序',
    dataType: 'number',
  },
];

export default fieldList;

/**
 * 组件配置（用于生成菜单数据）
 */
export const COMPONENTS: MenuComponent[] = [
  {
    title: '区域管理',
    component: () => import('./List.vue'),
    sort: 10,
    keepalive: true,
    icon: 'pin',
    permits: [`GET${basePath}/query`],
    elements: [
      { title: '新增', code: 'create', permits: [`POST${basePath}/create`] },
      { title: '更新', code: 'update', permits: [`POST${basePath}/update`, `GET${basePath}/detail`] },
      { title: '删除', code: 'remove', permits: [`POST${basePath}/remove`] },
      { title: '详情', code: 'detail', permits: [`GET${basePath}/detail`] },
      { title: '导入', code: 'import', permits: [`POST${basePath}/import`] },
      { title: '导出', code: 'export', permits: [`GET${basePath}/export`] },
    ],
  },
];
